﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FeedNet;
using System.IO;

namespace TestFeedNet
{
    /// <summary>
    /// Summary description for TestRSSParsing
    /// </summary>
    [TestClass]
    public class TestRSSParsing
    {
        Feed f;

        public TestRSSParsing()
        {
            
            string path = Path.Combine(Environment.CurrentDirectory, @"..\..\..\TestFeedNet\RSS_testcase.txt");
            Feeder testFeeder = new Feeder();
            FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);         
            f = testFeeder.getFeedFromStream(fs);
            fs.Close();
      
        }

        [TestMethod]
        public void testTitleParsing()
        {
            Assert.AreEqual("TechCrunch", f.title);
        }

        [TestMethod]
        public void testDescriptionParsing()
        {
            Assert.AreEqual("TechCrunch is a group-edited blog that profiles the companies, products and events defining and transforming the new web.", f.description);
        }

        [TestMethod]
        public void testUrlParsing()
        {
            Assert.AreEqual("http://www.techcrunch.com", f.url);
        }

        [TestMethod]
        public void testRSSFeedDate()
        {
            Assert.AreEqual(DateTime.Parse("Thu, 26 Mar 2009 18:18:34 +0000"), f.last_modified);
        }

        [TestMethod]
        public void testEntriesCorrectNumber()
        {
            Assert.AreEqual(25, f.entries.Count); 
        }

        [TestMethod]
        public void testEntryParse()
        {
            Entry myEntry = f.entries.First();
            Assert.AreEqual("What Could Go Wrong With Google: The Slideshow", myEntry.title);
            Assert.AreEqual("http://feedproxy.google.com/~r/Techcrunch/~3/uuWhY8eAWF8/", myEntry.url);
            Assert.AreEqual("Erick Schonfeld", myEntry.author);
            Assert.IsTrue(myEntry.description.StartsWith("<img src="));
            Assert.AreEqual(DateTime.Parse("Thu, 26 Mar 2009 18:09:23 +0000"), myEntry.date_published);
            Assert.AreEqual("<div style=", myEntry.content.Substring(0,11));
            
        }
    }
}
